package com.skyyan.netty.jjf.client.handler;

import com.skyyan.netty.jjf.client.MessageHandler;
import com.skyyan.netty.jjf.protocol.BalanceQueryMessage;
import com.skyyan.netty.jjf.protocol.Message;

/**
 * 余额查询消息处理器
 */
public class BalanceQueryMessageHandler implements MessageHandler {
    @Override
    public boolean canHandle(Message msg) {
        return msg instanceof BalanceQueryMessage;
    }
    
    @Override
    public void handle(Message msg) {
        if (msg instanceof BalanceQueryMessage.Downlink) {
            BalanceQueryMessage.Downlink downlink = (BalanceQueryMessage.Downlink) msg;
            System.out.println("余额查询下行报文:");
            System.out.println("  状态码: 0x" + String.format("%02X", downlink.getStatusCodeBCD()));
            System.out.println("  余额: " + downlink.getMoneyValue() + "分");
            System.out.println("  用户名: " + downlink.getUsername());
            System.out.println("  卡号: " + downlink.getCardNO());
        } else {
            System.out.println("余额查询上行报文");
        }
    }
}